package tables

import (
	"peilian-api/app/global/variable"
)

// 报告话术
// 现在报告的很多话术都是写死在代码文件当中，这里将这些话术存在数据库中，便于维护修改

var DefaultTrick = ReportVerbalTrick{}

type ReportVerbalTrick struct {
	Model
	Type     string `gorm:"type:varchar(50);comment:话术类型"`
	CareerID string `gorm:"type:varchar(100)"`
	Criteria string `gorm:"type:varchar(50);comment:维度"`
	Level    string `gorm:"type:varchar(20);comment:优/中/差"`
	Tag      string `gorm:"type:varchar(10);comment:A/B/C/D"`
	Text     string
	Desc     string `gorm:"type:varchar(100);comment:描述"`
}

func (rvt *ReportVerbalTrick) TableName() string {
	return "report_trick"
}

func (rvt *ReportVerbalTrick) GetSuggestTrick() (map[string]map[string]map[string]string, error) {
	suggestsComments := make(map[string]map[string]map[string]string)
	suggestTrick := make([]*ReportVerbalTrick, 0)
	if err := variable.DB.MySQL.Where("type=?", "suggest").Find(&suggestTrick).Error; err != nil {
		return nil, err
	}
	for _, s := range suggestTrick {
		_, exist := suggestsComments[s.CareerID]
		if !exist {
			suggestsComments[s.CareerID] = make(map[string]map[string]string)
		}
		_, exist2 := suggestsComments[s.CareerID][s.Criteria]
		if !exist2 {
			suggestsComments[s.CareerID][s.Criteria] = make(map[string]string)
		}
		suggestsComments[s.CareerID][s.Criteria][s.Tag] = s.Text
	}
	return suggestsComments, nil
}

func (rvt *ReportVerbalTrick) GetCommonSuggestTrick() (map[string]map[string]map[string]string, error) {
	commonSuggestComments := make(map[string]map[string]map[string]string)
	commonSuggestTrick := make([]*ReportVerbalTrick, 0)
	if err := variable.DB.MySQL.Where("type=?", "common_suggest").Find(&commonSuggestTrick).Error; err != nil {
		return nil, err
	}
	for _, c := range commonSuggestTrick {
		_, exist := commonSuggestComments[c.Criteria]
		if !exist {
			commonSuggestComments[c.Criteria] = make(map[string]map[string]string)
		}
		_, exist2 := commonSuggestComments[c.Criteria][c.Level]
		if !exist2 {
			commonSuggestComments[c.Criteria][c.Level] = make(map[string]string)
		}
		commonSuggestComments[c.Criteria][c.Level][c.Tag] = c.Text
	}
	return commonSuggestComments, nil
}

func (rvt *ReportVerbalTrick) GetAbilityTrick() (map[string]map[string]map[string]string, error) {
	commonSuggestComments := make(map[string]map[string]map[string]string)
	commonSuggestTrick := make([]*ReportVerbalTrick, 0)
	if err := variable.DB.MySQL.Where("type=?", "ability").Find(&commonSuggestTrick).Error; err != nil {
		return nil, err
	}
	for _, c := range commonSuggestTrick {
		_, exist := commonSuggestComments[c.CareerID]
		if !exist {
			commonSuggestComments[c.CareerID] = make(map[string]map[string]string)
		}
		_, exist2 := commonSuggestComments[c.CareerID][c.Criteria]
		if !exist2 {
			commonSuggestComments[c.CareerID][c.Criteria] = make(map[string]string)
		}
		commonSuggestComments[c.CareerID][c.Criteria][c.Tag] = c.Text
	}
	return commonSuggestComments, nil
}

func (rvt *ReportVerbalTrick) GetSkillTrick() (map[string]map[string]string, error) {
	commonSuggestComments := make(map[string]map[string]string, 100)
	commonSuggestTrick := make([]*ReportVerbalTrick, 0)
	if err := variable.DB.MySQL.Where("type=?", "skill").Find(&commonSuggestTrick).Error; err != nil {
		return nil, err
	}
	for _, c := range commonSuggestTrick {
		_, exists := commonSuggestComments[c.Criteria]
		if !exists {
			commonSuggestComments[c.Criteria] = make(map[string]string)
		}
		commonSuggestComments[c.Criteria][c.Tag] = c.Text

	}
	return commonSuggestComments, nil
}
